﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using SqlCon;

namespace yfxt
{
    public partial class ms_dfcfcx_mx : Form
    {

        //两个窗口传值
        public string s_dycf;
        public string S_dycf
        {
            get { return this.s_dycf; }
            set { this.s_dycf = value; }
        }



        public ms_dfcfcx dfcfcx;
        public string s_temp;
        public ms_dfcfcx_mx()
        {
            InitializeComponent();
        }
        SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction);

        private void button1_Click(object sender, EventArgs e)
        {
            dfcfcx = (ms_dfcfcx)this.Owner;//传值一定将传值的参数放在new 窗口之前

            s_temp = dfcfcx.s_cfhm_dgw;

            s_dycf = s_temp.ToString();

            ms_dycf dycf = new ms_dycf();

            dycf.Owner = this;

            dycf.ShowDialog();
        }

        private void ms_dfcfcx_mx_Load(object sender, EventArgs e)
        {
            dfcfcx = (ms_dfcfcx)this.Owner;//取得父窗口传值

            string s = dfcfcx.s_cfhm_dgw;

            string str = "select ypmc,ypgg,ypdw,cdmc,ypdj,ypsl from V_cf01_cf02_typk_ypcd_cddz where cfhm=" + s + " ";

            if (conn.State != ConnectionState.Open) { conn.Open(); }

            using (SqlCommand cmd = new SqlCommand(str, conn))
            {

                SqlDataAdapter da = new SqlDataAdapter();

                da.SelectCommand = cmd;

                DataTable dt = new DataTable();

                da.Fill(dt);

                dataGridView1.DataSource = dt;

                dataGridView1.Columns[0].HeaderCell.Value = "药品名称";
                dataGridView1.Columns[1].HeaderCell.Value = "药品规格";
                dataGridView1.Columns[2].HeaderCell.Value = "药品单位";
                dataGridView1.Columns[3].HeaderCell.Value = "药品产地";
                dataGridView1.Columns[4].HeaderCell.Value = "药品价格";
                dataGridView1.Columns[5].HeaderCell.Value = "药品数量";
            }

            SqlParameter sp_01, sp_02, sp_03, sp_04, sp_05, sp_06, sp_07, sp_08;

            string str_01 = "select @fphm=fphm,@brxm=brxm,@brxz=brxz,@kfrq=kfrq,@ksmc=ksmc,@ygxm=ygxm from V_cf01_ygdm_ksdm_brda where cfhm=@cfhm";

            if (conn.State != ConnectionState.Open) { conn.Open(); }

            using (SqlCommand cmd_01 = new SqlCommand(str_01, conn))
            {
                cmd_01.Parameters.AddWithValue("@cfhm", s.ToString());
                sp_01 = cmd_01.Parameters.Add("@brxm", SqlDbType.NVarChar, 40);
                sp_02 = cmd_01.Parameters.Add("@brxz", SqlDbType.NVarChar, 20);
                sp_03 = cmd_01.Parameters.Add("@kfrq", SqlDbType.DateTime, 40);
                sp_04 = cmd_01.Parameters.Add("@ksmc", SqlDbType.NVarChar, 40);
                sp_05 = cmd_01.Parameters.Add("@ygxm", SqlDbType.NVarChar, 40);
                sp_06 = cmd_01.Parameters.Add("@fphm", SqlDbType.NVarChar, 20);

                sp_01.Direction = ParameterDirection.Output;
                sp_02.Direction = ParameterDirection.Output;
                sp_03.Direction = ParameterDirection.Output;
                sp_04.Direction = ParameterDirection.Output;
                sp_05.Direction = ParameterDirection.Output;
                sp_06.Direction = ParameterDirection.Output;

                cmd_01.ExecuteNonQuery().ToString();


                tb_brxm.Text = sp_01.Value.ToString();
                if (sp_02.Value.ToString().Equals("123"))
                {
                    tb_brzx.Text = "自费";
                }
                else
                {

                    tb_brzx.Text = "医保";
                }

                tb_kfrq.Text = sp_03.Value.ToString();

                tb_fphm.Text = sp_06.Value.ToString();

                tb_ysxm.Text = sp_05.Value.ToString();

                tb_ypzs.Text = dataGridView1.Rows.Count.ToString();
            }




            string s_sum = "select @ypzqs=sum(ypsl*ypdj) from ms_cf01,ms_cf02 where ms_cf01.cfsb=ms_cf02.cfsb and cfhm=@cfhm";
            if (conn.State != ConnectionState.Open) { conn.Open(); }
            using (SqlCommand cmd_02 = new SqlCommand(s_sum, conn))
            {
                sp_07 = cmd_02.Parameters.Add("@ypzqs", SqlDbType.Money, 40);
                sp_08 = cmd_02.Parameters.AddWithValue("@cfhm", s.ToString());

                sp_07.Direction = ParameterDirection.Output;

                cmd_02.ExecuteNonQuery();

                tb_ypzqs.Text = sp_07.Value.ToString();
            }

            //MessageBox.Show(s);
        }
    }
}
